#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define getchar() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=getchar();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        x*=f;
    }
    char obuf[BUF],*p3=obuf;
    inline void pc(char ch){
        if(p3-obuf<BUF) *p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[32],ctop;
    template<typename T>inline void print(T x){
    	if(x<0) x=~x+1,pc('-');
        if(!x) return pc(48);
        while(x) ch[++ctop]=x%10^48,x/=10;
        while(ctop) pc(ch[ctop--]);
    }
    inline void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=5e4+5,inf=1e9;
int n,m,a[N],id[N],f[N];
vector<int> G[N];
int son[N],sz[N],dfn[N],xl[N],idx;
void dfs1(int p){
	sz[p]=1;
	xl[dfn[p]=++idx]=p;
	for(int v:G[p]){
		dfs1(v);
		sz[p]+=sz[v];
		if(sz[v]>sz[son[p]]) son[p]=v;
	}
}
int t1[N],t2[N];
inline void add1(int x){for(int y=x;x<=n&&t1[x]<y;x+=x&-x) t1[x]=y;}
inline int query1(int x){
	int ans=0;
	for(;x;x-=x&-x) ans=max(ans,t1[x]);
	return ans;
}
inline void clear1(int x){for(;x<=n&&t1[x];x+=x&-x) t1[x]=0;}
inline void add2(int x){for(int y=x;x&&t2[x]>y;x-=x&-x) t2[x]=y;}
inline int query2(int x){
	int ans=inf;
	for(;x<=n;x+=x&-x) ans=min(ans,t2[x]);
	return ans;
}
inline void clear2(int x){for(;x&&t2[x]<=n;x-=x&-x) t2[x]=inf;}
vector<pair<int,int>> P[N];
int lca;
inline void calc(int x){
	x=id[x];
	int k=query1(x);
	if(k) P[x].push_back({lca,k});
	k=query2(x);
	if(k<=n) P[k].push_back({lca,x});
}
void dfs2(int p,bool cl){
	if(!son[p]){
		if(!cl) add1(id[p]),add2(id[p]);
		return;
	}
	for(int v:G[p])
		if(v^son[p]) dfs2(v,1);
	dfs2(son[p],0);
	lca=p;
	calc(p),add1(id[p]),add2(id[p]);
	for(int v:G[p])if(v^son[p]){
		for(int i=dfn[v];i<dfn[v]+sz[v];++i) calc(xl[i]);
		for(int i=dfn[v];i<dfn[v]+sz[v];++i) add1(id[xl[i]]),add2(id[xl[i]]);
	}
	if(cl){
		for(int i=dfn[p];i<dfn[p]+sz[p];++i) clear1(id[xl[i]]),clear2(id[xl[i]]);
	}	
}
int l[N],ans[N],lt[N],t3[N];
inline void add3(int x,int v){for(;x;x-=x&-x) t3[x]+=v;}
inline int query3(int x){
	int ans=0;
	for(;x<=n;x+=x&-x) ans+=t3[x];
	return ans;
}
vector<int> Q[N];
int main(){
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
	read(n),read(m);
	for(int i=2;i<=n;++i){
		read(f[i]);
		G[f[i]].push_back(i);
	}
	for(int i=1;i<=n;++i) read(a[i]),id[a[i]]=i;
	dfs1(1);
	for(int i=1;i<=n;++i) t2[i]=inf;
	dfs2(1,0);
	for(int i=1,r;i<=m;++i){
		read(l[i]),read(r);
		Q[r].push_back(i); 
	}
	for(int i=1;i<=n;++i){
		P[i].push_back({a[i],i});
		for(auto p:P[i]){
			if(p.second>lt[p.first]) add3(lt[p.first],-1),add3(lt[p.first]=p.second,1);
		}
		for(int j:Q[i]) ans[j]=query3(l[j]);
	}
	for(int i=1;i<=m;++i) print(ans[i]),pc('\n');
	flush();
	return 0;
}

